package com.tianqu.tms.www.car.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsAction;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.www.car.controller.CarStockCountListTopController;
import com.tianqu.tms.www.car.viewhelper.CarStockCountListTopViewhelper;

/**
 * @author zhangxueliang
 * 
 * 库存统计列表
 */
public class CarStockCountListTopAction extends TmsAction{
	private Logger logger = Logger.getLogger(CarStockCountListTopAction.class);

	
	@Override
	protected ActionForward doAction(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response,
			UserContext uc) throws Exception {		
		
		CarStockCountListTopViewhelper view = new CarStockCountListTopViewhelper();
	    uc.setAttribute(TmsConstants.VIEWHELP, view);
	    //
		CarStockCountListTopController controller = new CarStockCountListTopController();
		controller.countStock(uc);
		
		String floor = request.getParameter("floor");
		if (floor != null) {
			controller.countCarInfoByFloor(uc, Integer.valueOf(floor));
		}
		
		view = (CarStockCountListTopViewhelper)uc.getAttribute(TmsConstants.VIEWHELP);
		view.setCarInCount(Integer.valueOf(uc.getAttribute("carInCount").toString()));
		view.setCarOutCount(Integer.valueOf(uc.getAttribute("carOutCount").toString()));
		view.setCarTotalInventory(Integer.valueOf(uc.getAttribute("carTotalInventory").toString()));
		request.setAttribute(TmsConstants.VIEWHELP, view);
		
		uc.removeAttribute(TmsConstants.VIEWHELP);
		logger.debug(this.getClass().getName() + "#doAction was completed.");
		return mapping.findForward(TmsConstants.SUCCESS);
	}

}
